package au.com.bus4u.controller.pc;


import au.com.bus4u.controller.BaseController;
import au.com.bus4u.service.OrderOldService;
import au.com.bus4u.service.UserService;
import au.com.bus4u.utils.JsonResult;
import au.com.bus4u.utils.PageData;
import com.github.pagehelper.PageInfo;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/order_old")
@Log
public class OrderOldController extends BaseController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserService userService;
    @Autowired
    private OrderOldService orderOldService;
    @Value("${min-auction-amount}")
    private Double minAuctionAmount;

    /**
     * 查询订单
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/list")
    public JsonResult<Map> list()throws Exception{
        log.info("=========================================");
        PageData pageData = getPageData();
        Map<String, Object> result = new HashMap<>();
        List<PageData> list = orderOldService.list(pageData);
        result.put("list",list);
        return new JsonResult<Map>(SUCCESS, result);
    }


    /**
     * 新增订单
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult<Map> save()throws Exception{
        log.info("=========================================");
        PageData pageData = getPageData();
        Map<String, Object> result = new HashMap<>();
        orderOldService.save(pageData);
        return new JsonResult<Map>(SUCCESS, result);
    }

    /**
     * 修改订单
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult<Map> update()throws Exception{
        log.info("=========================================");
        PageData pageData = getPageData();
        Map<String, Object> result = new HashMap<>();

        orderOldService.edit(pageData);
        return new JsonResult<Map>(SUCCESS, result);
    }
    /**
     * 删除订单
     * @return
     * @throws Exception
     */
//    @RequiresPermissions("sys:log:content")    //只有当用户拥有这个sys:log:content字符串时才能访问此方法。info.setStringPermissions
//    @RequiresPermissions(value={"add","update"},logical = Logical.AND)
//    @RequiresPermissions({"file:read", "write:aFile.txt"} )
// 要求subject中必须同时含有file:read和write:aFile.txt的权限才能执行方法。否则抛出异常AuthorizationException。

//    @RequiresRoles(value={"manage","user"},logical = Logical.OR)           //OR，表示所列出的条件只要满足其中一个就可以，如果不写或者设置成logical = Logical.AND，表示所有列出的都必须满足才能进入方法。
//    @RequiresRoles("aRoleName")       //如果subject中有aRoleName角色才可以访问方法someMethod。如果没有这个权限则会抛出异常AuthorizationException。


//    @RequiresGuest        //验证是否是一个guest的请求，与@RequiresUser完全相反。换言之，RequiresUser  == !RequiresGuest。此时subject.getPrincipal() 结果为null.
//    @RequiresUser             //验证用户是否被记忆，user有两种含义：一种是成功登录的（subject.isAuthenticated() 结果为true）；另外一种是被记忆的（subject.isRemembered()结果为true）。
//    @RequiresAuthentication       //验证用户是否登录，等同于方法subject.isAuthenticated() 结果为true时。
    @ResponseBody
    @RequestMapping("/delete")
    public JsonResult<Map> delete(String IDS)throws Exception{
        log.info("=========================================");
        Map<String, Object> result = new HashMap<>();
        String[] ids = IDS.split(",");
        orderOldService.deleteAll(ids);
        return new JsonResult<Map>(SUCCESS, result);
    }














}
